package lium.lbs.lbsim.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.cjt2325.cameralibrary.util.LogUtil;
import com.lmlibrary.Constants;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import lium.lbs.lbsim.activity.SetGroupActivity;
import lium.lbs.lbsim.listener.PayMessageEven;
import lium.lbs.lbsim.pay.ChoosePayWayActivity;
import lium.lbs.lbsim.utils.SpUtils;
import org.greenrobot.eventbus.EventBus;


public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {


    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, "wx18dbe14ee98ecb20");
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }


    @Override
    public void onResp(BaseResp resp) {

        LogUtil.e("----------------onResp支付 - errCode:" + resp.errCode);
        LogUtil.e("----------------onResp支付 - errCode:" + resp.getType());

        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            if (resp.errCode == 0) {
                SpUtils.getInstance().put(Constants.WXPAYRE, true);
                Toast.makeText(this, "微信支付成功", Toast.LENGTH_LONG).show();
                finishActivity(100);

            } else {
                SpUtils.getInstance().put(Constants.WXPAYRE, false);
                Toast.makeText(this, "微信支付失败", Toast.LENGTH_LONG).show();
            }
            finish();
        }
    }

    @Override
    public void onReq(BaseReq baseReq) {

    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}